import logging
import time

import our_global

logger = logging.getLogger()
formatter = logging.Formatter('%(asctime)s %(filename)s %(funcName)s [line:%(lineno)d] %(levelname)s [%(message)s]')

# 设置屏幕打印的格式
sh = logging.StreamHandler()
sh.setFormatter(formatter)
logger.addHandler(sh)

# 设置log保存
localtime = time.strftime("%Y-%m-%d", time.localtime())
fh = logging.FileHandler(f"{our_global.root}/log/{localtime}.log", encoding='utf8')
fh.setFormatter(formatter)
logger.addHandler(fh)


def log_i(data):
    logger.setLevel(logging.INFO)  # 设置打印级别
    logging.info(data)


def log_e(data):
    logger.setLevel(logging.ERROR)  # 设置打印级别
    logging.info(data)


def log_d(data):
    logger.setLevel(logging.DEBUG)  # 设置打印级别
    logging.info(data)
